To print a linked
list, the traversal function is almost the same. It is necessary to ensure that the last
element is printed after the while
loop terminates.
An example shown
here is a simple function to add up all of the integers in a single
dimensioned array.
The final output is
necessary because the while loop will not run once it reaches the last node,
but it will still be necessary to output the contents of the next node.
Consequently, the last output deals with this.